"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var WaterFall = /** @class */ (function () {
    /**
     * 提供列数与元素宽度,让代码自动计算边距
     * @param {Vue} container 容器对象
     * @param {number} elWidth 单个元素的宽度
     * @param {object} lists 要排列的元素的对象
     * @param {number} column 要摆放的列数
     */
    function WaterFall(container, elWidth, lists, column) {
        this._lists = lists;
        this._container = container;
        this._elWidth = elWidth;
        this._column = column === undefined ? WaterFall.computedColumn(this._container, this._elWidth) : column;
    }
    Object.defineProperty(WaterFall.prototype, "lists", {
        /**
         * @return {IList[]} value
         */
        get: function () {
            return this._lists;
        },
        /**
         * @param {IList[]} value
         */
        set: function (value) {
            this._lists = value;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * 将id不重复的对象压入_lists中,并初始化isPosition的值
     * @param {IList[]} value
     */
    WaterFall.prototype.add = function (value) {
        for (var i = 0, length_1 = value.length; i < length_1; i++) {
            value[i].isPosition = false;
            if (this._lists[i].id !== value[i].id)
                this._lists.push(value[i]);
        }
    };
    /**
     * 移除指定区间的元素
     * @param {number} begin
     * @param {number} end
     */
    WaterFall.prototype.remove = function (begin, end) {
        var _end = end > this._lists.length ? this._lists.length - 1 : end;
        this._lists.splice(begin, _end);
    };
    /**
     * 计算填充剩余空间所需要的缩放大小
     * @param {HTMLElement} el 瀑布流容器
     * @param {number} elWidth 单个元素的宽度
     * @param {number} column 要摆放的列数
     * @return {number} result
     */
    WaterFall.widthFill = function (el, elWidth, column) {
        var _column = column - 1;
        var surplusWidth = (el.clientWidth - elWidth) - (_column * elWidth);
        return (surplusWidth / _column);
    };
    /**
     * 计算列数
     */
    WaterFall.computedColumn = function (container, elWidth) {
        return Math.floor((container.$el.clientWidth / elWidth));
    };
    WaterFall.prototype.setOffset = function (offset) {
        offset = offset === undefined ? { offsetTop: 0 } : offset;
        var offsetTop = offset.offsetTop;
        this.offsetTop = offsetTop;
    };
    /**
     * 计算各个元素的位置
     * @param {IList}value 需要排序的元素列表
     * @param {IOffset}offset 元素边距
     * @return {IList[]} value 以计算的元素
     */
    WaterFall.prototype.position = function (value, offset) {
        if (value === void 0) { value = this._lists; }
        this._left = WaterFall.widthFill(this._container.$el, this._elWidth, this._column);
        this.setOffset(offset);
        var column = this._column;
        this.add(value);
        if (!value[0].isPosition) {
            value[0].top = value[0].left = 0;
            value[0].width = this._elWidth;
            value[0].isPosition = true;
        }
        for (var i = 1, length_2 = value.length; i < length_2; i++) {
            if (i < column && !value[i].isPosition) {
                value[i].top = 0;
                value[i].left = this._elWidth * (i % column) + this._left * (i % column);
                value[i].width = this._elWidth;
                value[i].isPosition = true;
            }
            else if (!value[i].isPosition) {
                value[i].top = (value[i - column].top + value[i - column].el.clientHeight) + this.offsetTop;
                value[i].left = this._elWidth * (i % column) + this._left * (i % column);
                value[i].width = this._elWidth;
                value[i].isPosition = true;
            }
        }
        return value;
    };
    return WaterFall;
}());
exports.WaterFall = WaterFall;
